import os
import glob
import pytest
from Tools.demo.mcast import sender

# from utils.log import Logger
from utils.Send import mail
import logging
from utils.path_utils import path_utils

path_util = path_utils.get_report_path('allure-results')
path_utilo = path_utils.get_report_path('allure-report')
send = path_utils.get_report_path('results.html')


def run():
    test_files = glob.glob('./case/testcase*.py')
    if not test_files:
        raise FileNotFoundError("未找到测试文件，请检查路径或命名规则！")
    # 生成原始测试数据
    pytest.main(['-v', *test_files, '--alluredir', path_util, '--clean-alluredir'])
    # 生成持久化HTML报告
    os.system(f'allure generate {path_util} -o {path_utilo} --clean')
    # 自动打开报告
    os.system(f'allure open {path_utilo}')
    # 发送报告
    contents = [f'{send}']
    # mail(user='2652494214@qq.com',
    #      password='dhezfeypojmvdhji',
    #      host='smtp.qq.com',
    #      to='2652494214@qq.com',
    #      subject='酒仙网搜索并下单业务',
    #      contents=contents)


if __name__ == '__main__':
    run()
